filename = 'programming.txt'

with open(filename, 'w') as file_object: # 'w'指定打开方式，'w'写入，'r'读取，'a'附加，'r+'读写，默认为只读
    file_object.write("I love programming.\n")
    file_object.write("I love creating new games.\n")
    # write()不会自动添加换行符，如需换行，需要自己加换行符\n

# python只能将字符串写入文本文件，写入其他类型需要先转化为str类型

with open(filename, 'a') as file_object: # 'a'打开方式为附加，write()会添加在文件最后
    file_object.write("I also love finding meaning in large datasets.\n")
    file_object.write("I love creating apps that can run in a browser.\n")